﻿// ***********************************************************************
// Assembly         : DonNicky.Common.NET4
// Author           : donnicky
// Created          : 11-29-2012
//
// Last Modified By : donnicky
// Last Modified On : 11-29-2012
// ***********************************************************************
using System.ComponentModel.DataAnnotations;
using System.IO;

namespace DonNicky.Common.Validation
{
    /// <summary>
    /// Checks directory existence
    /// </summary>
    public class DirectoryExistsAttribute : ValidationAttribute
    {
        /// <summary>
        /// Determines whether the specified directory exists.
        /// </summary>
        /// <param name="value">The directory path to validate.</param>
        /// <returns>true if the specified directory path exists (or provided value is null or empty); otherwise, false.</returns>
        public override bool IsValid(object value)
        {
            return value == null || string.IsNullOrEmpty(value.ToString()) || Directory.Exists(value.ToString());
        }
    }
}
 
